# FILE: CurrencyManager.py
# DESC: Responsible for managing a collection of Currency objects

# TODO: Move common code (e.g. loading from file) to EntityManager

from EntityFactory import EntityFactory
from web.entity.Currency import Currency

class CurrencyManager(EntityFactory):

	def __init__(self):
		# TODO: load currencies from etc/currency.csv
		self.currencies_ = {} 
		self.currencies_["EUR"] = Currency("EUR", "", "&euro;")
		self.strRef_ = None


	def getCurrencies(self):
		return self.currencies_.itervalues()


	def validate(self, argv):
		rv = True
		if self.currencies_.has_key(argv):
			self.strRef_ = argv
		else:
			self.errMsg_ = "\"%s\" not found in currency dictionary." % argv
			rv = False
		
		return rv


	def doCreateEntity(self, consumer, relevanceFactor):
		currency = self.currencies_[self.strRef_]
		if consumer:
			consumer.onCurrency(currency)
		return currency


	def getEntityType(self):
		# TODO: add all the currency strings supported e.g. "EUR|USD|CAD"
		return "EUR"
